package org.tangolyricstagger.model;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.CompareToBuilder;

@Getter
@RequiredArgsConstructor
@ToString
public class TagInfo implements Comparable<TagInfo> {

	private final File file;
	private final String completeTitle;
	private final String artist;
	private final String genre;
	private final String year;
	private List<String> possibleTitles = new ArrayList<String>();

	public void cleanTitle(String separatorChars) {
		String title = completeTitle;
		title = StringUtils.lowerCase(title);
		title = StringUtils.trim(title);
		title = StringUtils.replaceChars(title, "éáíóú", "eaiou");
		title = StringUtils.replaceChars(title, ",.!?", "");
		title = StringUtils.remove(title, 'ñ');

		possibleTitles.add(title);
		possibleTitles.addAll(splitIntoListAndTrim(title, separatorChars));
	}

	@Override
	public int compareTo(TagInfo o) {
		return new CompareToBuilder().append(this.completeTitle, o.completeTitle).toComparison();
	}

	public List<String> splitIntoListAndTrim(String str, String separatorChars) {
		String[] split = StringUtils.split(str, separatorChars);
		for (int i = 0; i < split.length; i++) {
			split[i] = StringUtils.trim(split[i]);
		}
		return Arrays.asList(split);
	}
}
